package com.mszl.blog.controller;

import com.mszl.blog.entity.ArticleTag;
import com.mszl.blog.service.ArticleTagService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("articleTag")
public class ArticleTagController {
    @Resource
    private ArticleTagService articleTagService;

    @GetMapping
    public ResponseEntity<Page<ArticleTag>> queryByPage(ArticleTag articleTag, PageRequest pageRequest) {
        return ResponseEntity.ok(this.articleTagService.queryByPage(articleTag, pageRequest));
    }

    @GetMapping("{id}")
    public ResponseEntity<ArticleTag> queryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.articleTagService.queryById(id));
    }

    @PostMapping
    public ResponseEntity<ArticleTag> add(@RequestBody ArticleTag articleTag) {
        return ResponseEntity.ok(this.articleTagService.insert(articleTag));
    }

    @PutMapping
    public ResponseEntity<ArticleTag> edit(@RequestBody ArticleTag articleTag) {
        return ResponseEntity.ok(this.articleTagService.update(articleTag));
    }

    @DeleteMapping("{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable Long id) {
        return ResponseEntity.ok(this.articleTagService.deleteById(id));
    }
}
